package com.algebra.util.sensitive;

import java.util.HashMap;
import java.util.Map;

/**
 * @author al
 * @date 2022/5/25 11:32
 * @description
 */
public class RequestDataTransfer {

    private static final ThreadLocal<Map<String, Object>> REQUEST_DATA = new ThreadLocal<>();

    public RequestDataTransfer() {
    }

    public static void put(Map<String, Object> requestData) {
        REQUEST_DATA.set(requestData);
    }

    public static void put(final String key, final Object value) {
        Map<String, Object> dataMap = getAll();
        if (null != dataMap && !dataMap.isEmpty()) {
            dataMap.put(key, value);
        } else {
            put(new HashMap<String, Object>(16) {
                {
                    this.put(key, value);
                }
            });
        }

    }

    public static Object get(String param) {
        Map<String, Object> dataMap = getAll();
        return null != dataMap && !dataMap.isEmpty() ? dataMap.get(param) : null;
    }

    public static Map<String, Object> getAll() {
        return REQUEST_DATA.get();
    }

    public static void remove() {
        REQUEST_DATA.remove();
    }

    public static void skipSensitive() {
        put("skip_sensitive", "1");
    }
}
